package com.hzsk.lisence.controller;

import com.hzsk.lisence.entity.query.IDCInfoQuery;
import com.hzsk.lisence.entity.response.IncResponce;
import com.hzsk.lisence.service.IDCService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/lisence/idc")
@CrossOrigin
public class IDCController {


    @Resource
    public IDCService idcService;

    @PostMapping("/checkstaffauthority")
    @ApiOperation(value = "检测员工权限")
    public IncResponce checkStaffAuthority(@RequestBody IDCInfoQuery idcInfoQuery){

        IncResponce incResponce = new IncResponce();
        try {
            idcService.checkStaffAuthority(incResponce ,idcInfoQuery);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }


    @PostMapping("/checkemukeyauthority")
    @ApiOperation(value = "检测U盾权限")
    public IncResponce checkEmUkeyAuthority(@RequestBody IDCInfoQuery idcInfoQuery){
        IncResponce incResponce = new IncResponce();
        try {
            idcService.checkEmUkeyAuthority(incResponce ,idcInfoQuery);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }


    @PostMapping("/getidcwritecommand")
    @ApiOperation(value = "获取写口令")
    public IncResponce getIdcWriteCommand(@RequestBody IDCInfoQuery idcInfoQuery){
        IncResponce incResponce = new IncResponce();
        try {
            idcService.getIdcWriteCommand(incResponce ,idcInfoQuery);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }



    @PostMapping("/getdeviceidbycommandandidcid")
    @ApiOperation(value = "获取设备ID")
    public IncResponce getDeviceIdByCommandAndIdcId(@RequestBody IDCInfoQuery idcInfoQuery){
        IncResponce incResponce = new IncResponce();
        try {
            idcService.getWriteCommandByChipId(incResponce,idcInfoQuery);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }



    @PostMapping("/updatestatus")
    @ApiOperation(value = "更新IDC制作状态")
    public IncResponce updateIDCStatus(@RequestBody IDCInfoQuery idcInfoQuery){
        IncResponce incResponce = new IncResponce();
        try {
            idcService.updateIDCStatus(incResponce,idcInfoQuery);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }



    @PostMapping("/getidcinfobyproduceplan")
    @ApiOperation(value = "查看IDC制作详情")
    public IncResponce getIDCInfoByProducePlan(@RequestBody IDCInfoQuery idcInfoQuery){
        IncResponce incResponce = new IncResponce();
        try {
            idcService.getIDCInfoByProducePlan(incResponce,idcInfoQuery);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }



    @PostMapping("/getemukeyuseinfo")
    @ApiOperation(value = "查看U盾使用详情")
    public IncResponce getEmUKeyUseInfo(@RequestBody IDCInfoQuery idcInfoQuery){
        IncResponce incResponce = new IncResponce();
        try {
            idcService.getemUKeyUseInfo(incResponce,idcInfoQuery);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }



}
